import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue';
import router from '../src/router/index.js'
import store from './store';
import "./api/mock"
import Cookies  from 'js-cookie';

Vue.use(ElementUI);

// 添加全局前置导航守卫
  router.beforeEach((to, from, next) => {
    // 判断token是否存在
   const token= Cookies.get('token')
   //token不存在，说明未登录，跳转至登陆页
   if(!token&&to.name!=='login'){
     next({name:'login'})
   }
   else if(token&&to.name==='login')//token存在，用户登录，跳转到首页
   {
     next({name:'home'})
   }
   else{
    next();
   }
  })

new Vue({
  store,
  router,
  render: h => h(App)
}).$mount('#app')